{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "nba = pd.read_csv('./file/chapter_04/nba.csv', parse_dates=[\"Birthday\"], date_format={\"Birthday\": 'mixed'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(450, 5)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name                object\n",
       "Team                object\n",
       "Position            object\n",
       "Birthday    datetime64[ns]\n",
       "Salary               int64\n",
       "dtype: object"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ndim 属性返回 Pandas 对象中的维数\n",
    "nba.ndim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(450, 5)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# shape 属性以元组的形式返回 Dataframe 的维度\n",
    "nba.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2250"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# size 属性计算数据集里值得总数，包含 NaN 的值\n",
    "nba.size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name        450\n",
       "Team        450\n",
       "Position    450\n",
       "Birthday    450\n",
       "Salary      450\n",
       "dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用 count 排除缺失值,返回一个 Series，包含每列中现值（非空值）的个数\n",
    "nba.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2250"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 可以使用 sum 方法将所有 Series 值相加，得出 DataFtame 中非空值的数量 sum 后的值与 size 属性一致，说明没有空值\n",
    "nba.count().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     A  B\n",
       "0  1.0  2\n",
       "1  NaN  3"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建一个带有空值的 DataFrame\n",
    "import numpy as np\n",
    "data = {\"A\":[1,np.nan],'B':[2,3]}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# size 属性为4\n",
    "df.size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# count 值为3\n",
    "df.count().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Shake Milton</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Christian Wood</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>PJ Washington</td>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Derrick Rose</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Marial Shayok</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             Name                Team Position   Birthday   Salary\n",
       "0    Shake Milton  Philadelphia 76ers       SG 1996-09-26  1445697\n",
       "1  Christian Wood     Detroit Pistons       PF 1995-09-27  1645357\n",
       "2   PJ Washington   Charlotte Hornets       PF 1998-08-23  3831840\n",
       "3    Derrick Rose     Detroit Pistons       PG 1988-10-04  7317074\n",
       "4   Marial Shayok  Philadelphia 76ers        G 1995-07-26    79568"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# head 方法从 DataFrame 的顶部提取行\n",
    "nba.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>447</th>\n",
       "      <td>Robin Lopez</td>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>4767000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>448</th>\n",
       "      <td>Collin Sexton</td>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1999-01-04</td>\n",
       "      <td>4764960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>449</th>\n",
       "      <td>Ricky Rubio</td>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-10-21</td>\n",
       "      <td>16200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Name                 Team Position   Birthday    Salary\n",
       "447    Robin Lopez      Milwaukee Bucks        C 1988-04-01   4767000\n",
       "448  Collin Sexton  Cleveland Cavaliers       PG 1999-01-04   4764960\n",
       "449    Ricky Rubio         Phoenix Suns       PG 1990-10-21  16200000"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# tail 从 DataFrame 的尾部提取行\n",
    "nba.tail(n=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>445</th>\n",
       "      <td>Austin Rivers</td>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1992-08-01</td>\n",
       "      <td>2174310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>446</th>\n",
       "      <td>Harry Giles</td>\n",
       "      <td>Sacramento Kings</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-04-22</td>\n",
       "      <td>2578800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>447</th>\n",
       "      <td>Robin Lopez</td>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>4767000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>448</th>\n",
       "      <td>Collin Sexton</td>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1999-01-04</td>\n",
       "      <td>4764960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>449</th>\n",
       "      <td>Ricky Rubio</td>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-10-21</td>\n",
       "      <td>16200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Name                 Team Position   Birthday    Salary\n",
       "445  Austin Rivers      Houston Rockets       PG 1992-08-01   2174310\n",
       "446    Harry Giles     Sacramento Kings       PF 1998-04-22   2578800\n",
       "447    Robin Lopez      Milwaukee Bucks        C 1988-04-01   4767000\n",
       "448  Collin Sexton  Cleveland Cavaliers       PG 1999-01-04   4764960\n",
       "449    Ricky Rubio         Phoenix Suns       PG 1990-10-21  16200000"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# tail 从 DataFrame 的尾部提取行，默认提取5行\n",
    "nba.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>215</th>\n",
       "      <td>Jrue Holiday</td>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-06-12</td>\n",
       "      <td>26131111</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             Name                  Team Position   Birthday    Salary\n",
       "215  Jrue Holiday  New Orleans Pelicans       PG 1990-06-12  26131111"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# simple 方法从 DataFrame 中随机抽取数据行\n",
    "nba.sample()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>218</th>\n",
       "      <td>Jared Harper</td>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>1997-09-14</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>146</th>\n",
       "      <td>OG Anunoby</td>\n",
       "      <td>Toronto Raptors</td>\n",
       "      <td>SF</td>\n",
       "      <td>1997-07-17</td>\n",
       "      <td>2281800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>Otto Porter</td>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>SF</td>\n",
       "      <td>1993-06-03</td>\n",
       "      <td>27250576</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             Name             Team Position   Birthday    Salary\n",
       "218  Jared Harper     Phoenix Suns       PG 1997-09-14     79568\n",
       "146    OG Anunoby  Toronto Raptors       SF 1997-07-17   2281800\n",
       "26    Otto Porter    Chicago Bulls       SF 1993-06-03  27250576"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# simple 方法从 DataFrame 中随机抽取数据行.第一个参数制定提取数据的行数\n",
    "nba.sample(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name        450\n",
       "Team         30\n",
       "Position      9\n",
       "Birthday    430\n",
       "Salary      269\n",
       "dtype: int64"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# nunique 方法来计算 DataFrame 那个唯一值的数量\n",
    "nba.nunique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name             Zylan Cheatham\n",
       "Team         Washington Wizards\n",
       "Position                     SG\n",
       "Birthday    2000-12-23 00:00:00\n",
       "Salary                 40231758\n",
       "dtype: object"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# max 方法返回一个 Series ，其中包含每列的最大值\n",
    "nba.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name               Aaron Gordon\n",
       "Team              Atlanta Hawks\n",
       "Position                      C\n",
       "Birthday    1977-01-26 00:00:00\n",
       "Salary                    79568\n",
       "dtype: object"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# min 方法返回一个 Series ，其中包含每列的最小值（最小的数字，最接近字母表开头的字符串，最早的日期）\n",
    "nba.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>205</th>\n",
       "      <td>Stephen Curry</td>\n",
       "      <td>Golden State Warriors</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-03-14</td>\n",
       "      <td>40231758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>Chris Paul</td>\n",
       "      <td>Oklahoma City Thunder</td>\n",
       "      <td>PG</td>\n",
       "      <td>1985-05-06</td>\n",
       "      <td>38506482</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>219</th>\n",
       "      <td>Russell Westbrook</td>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-11-12</td>\n",
       "      <td>38506482</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>251</th>\n",
       "      <td>John Wall</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-09-06</td>\n",
       "      <td>38199000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Name                   Team Position   Birthday    Salary\n",
       "205      Stephen Curry  Golden State Warriors       PG 1988-03-14  40231758\n",
       "38          Chris Paul  Oklahoma City Thunder       PG 1985-05-06  38506482\n",
       "219  Russell Westbrook        Houston Rockets       PG 1988-11-12  38506482\n",
       "251          John Wall     Washington Wizards       PG 1990-09-06  38199000"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数据集中收入最高的4个球员\n",
    "nba.nlargest(n=4, columns=['Salary'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>136</th>\n",
       "      <td>Sekou Doumbouya</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>SF</td>\n",
       "      <td>2000-12-23</td>\n",
       "      <td>3285120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>432</th>\n",
       "      <td>Talen Horton-Tucker</td>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>GF</td>\n",
       "      <td>2000-11-25</td>\n",
       "      <td>898310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>Zion Williamson</td>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>F</td>\n",
       "      <td>2000-07-06</td>\n",
       "      <td>9757440</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    Name                  Team Position   Birthday   Salary\n",
       "136      Sekou Doumbouya       Detroit Pistons       SF 2000-12-23  3285120\n",
       "432  Talen Horton-Tucker    Los Angeles Lakers       GF 2000-11-25   898310\n",
       "137      Zion Williamson  New Orleans Pelicans        F 2000-07-06  9757440"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 寻找年龄最大的3名球员\n",
    "nba.nlargest(n=3,columns=['Birthday'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Salary    3444112694\n",
       "dtype: int64"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用 sum 方法计算所有 Nba 球员的薪资综合.numeric_only 表示只对数字字段进行加总\n",
    "nba.sum(numeric_only=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Salary    7.653584e+06\n",
       "dtype: float64"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用 mean 计算球员的平均工资\n",
    "nba.mean(numeric_only=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Salary    3303074.5\n",
       "dtype: float64"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算工资中位数\n",
    "nba.median(numeric_only=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Salary\n",
       "0   79568"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算众数\n",
    "nba.mode(numeric_only=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Salary    9.288810e+06\n",
       "dtype: float64"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#计算标准差\n",
    "nba.std(numeric_only=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 4.3 对DataFrame 进行排序\n",
    "# 数据集的行以混乱的随机顺序排列时，可以使用 sort_values 方法按一列或多列对DataFrame 进行排序\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>Aaron Gordon</td>\n",
       "      <td>Orlando Magic</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-16</td>\n",
       "      <td>19863636</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>Aaron Holiday</td>\n",
       "      <td>Indiana Pacers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1996-09-30</td>\n",
       "      <td>2239200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>437</th>\n",
       "      <td>Abdel Nader</td>\n",
       "      <td>Oklahoma City Thunder</td>\n",
       "      <td>SF</td>\n",
       "      <td>1993-09-25</td>\n",
       "      <td>1618520</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>Adam Mokoka</td>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>G</td>\n",
       "      <td>1998-07-18</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>399</th>\n",
       "      <td>Admiral Schofield</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>SF</td>\n",
       "      <td>1997-03-30</td>\n",
       "      <td>1000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159</th>\n",
       "      <td>Zach LaVine</td>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>PG</td>\n",
       "      <td>1995-03-10</td>\n",
       "      <td>19500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>302</th>\n",
       "      <td>Zach Norvell</td>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1997-12-09</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>312</th>\n",
       "      <td>Zhaire Smith</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1999-06-04</td>\n",
       "      <td>3058800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>Zion Williamson</td>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>F</td>\n",
       "      <td>2000-07-06</td>\n",
       "      <td>9757440</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248</th>\n",
       "      <td>Zylan Cheatham</td>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>SF</td>\n",
       "      <td>1995-11-17</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Name                   Team Position   Birthday    Salary\n",
       "52        Aaron Gordon          Orlando Magic       PF 1995-09-16  19863636\n",
       "101      Aaron Holiday         Indiana Pacers       PG 1996-09-30   2239200\n",
       "437        Abdel Nader  Oklahoma City Thunder       SF 1993-09-25   1618520\n",
       "81         Adam Mokoka          Chicago Bulls        G 1998-07-18     79568\n",
       "399  Admiral Schofield     Washington Wizards       SF 1997-03-30   1000000\n",
       "..                 ...                    ...      ...        ...       ...\n",
       "159        Zach LaVine          Chicago Bulls       PG 1995-03-10  19500000\n",
       "302       Zach Norvell     Los Angeles Lakers       SG 1997-12-09     79568\n",
       "312       Zhaire Smith     Philadelphia 76ers       SG 1999-06-04   3058800\n",
       "137    Zion Williamson   New Orleans Pelicans        F 2000-07-06   9757440\n",
       "248     Zylan Cheatham   New Orleans Pelicans       SF 1995-11-17     79568\n",
       "\n",
       "[450 rows x 5 columns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按照姓名字母顺序排序\n",
    "nba.sort_values(by=['Name'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>Aaron Gordon</td>\n",
       "      <td>Orlando Magic</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-16</td>\n",
       "      <td>19863636</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>Aaron Holiday</td>\n",
       "      <td>Indiana Pacers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1996-09-30</td>\n",
       "      <td>2239200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>437</th>\n",
       "      <td>Abdel Nader</td>\n",
       "      <td>Oklahoma City Thunder</td>\n",
       "      <td>SF</td>\n",
       "      <td>1993-09-25</td>\n",
       "      <td>1618520</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>Adam Mokoka</td>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>G</td>\n",
       "      <td>1998-07-18</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>399</th>\n",
       "      <td>Admiral Schofield</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>SF</td>\n",
       "      <td>1997-03-30</td>\n",
       "      <td>1000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159</th>\n",
       "      <td>Zach LaVine</td>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>PG</td>\n",
       "      <td>1995-03-10</td>\n",
       "      <td>19500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>302</th>\n",
       "      <td>Zach Norvell</td>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1997-12-09</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>312</th>\n",
       "      <td>Zhaire Smith</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1999-06-04</td>\n",
       "      <td>3058800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>Zion Williamson</td>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>F</td>\n",
       "      <td>2000-07-06</td>\n",
       "      <td>9757440</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248</th>\n",
       "      <td>Zylan Cheatham</td>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>SF</td>\n",
       "      <td>1995-11-17</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Name                   Team Position   Birthday    Salary\n",
       "52        Aaron Gordon          Orlando Magic       PF 1995-09-16  19863636\n",
       "101      Aaron Holiday         Indiana Pacers       PG 1996-09-30   2239200\n",
       "437        Abdel Nader  Oklahoma City Thunder       SF 1993-09-25   1618520\n",
       "81         Adam Mokoka          Chicago Bulls        G 1998-07-18     79568\n",
       "399  Admiral Schofield     Washington Wizards       SF 1997-03-30   1000000\n",
       "..                 ...                    ...      ...        ...       ...\n",
       "159        Zach LaVine          Chicago Bulls       PG 1995-03-10  19500000\n",
       "302       Zach Norvell     Los Angeles Lakers       SG 1997-12-09     79568\n",
       "312       Zhaire Smith     Philadelphia 76ers       SG 1999-06-04   3058800\n",
       "137    Zion Williamson   New Orleans Pelicans        F 2000-07-06   9757440\n",
       "248     Zylan Cheatham   New Orleans Pelicans       SF 1995-11-17     79568\n",
       "\n",
       "[450 rows x 5 columns]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按照姓名字母顺序排序\n",
    "# nba.sort_values('Name')\n",
    "nba.sort_values(by='Name')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>248</th>\n",
       "      <td>Zylan Cheatham</td>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>SF</td>\n",
       "      <td>1995-11-17</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>Zion Williamson</td>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>F</td>\n",
       "      <td>2000-07-06</td>\n",
       "      <td>9757440</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>312</th>\n",
       "      <td>Zhaire Smith</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1999-06-04</td>\n",
       "      <td>3058800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>302</th>\n",
       "      <td>Zach Norvell</td>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1997-12-09</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159</th>\n",
       "      <td>Zach LaVine</td>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>PG</td>\n",
       "      <td>1995-03-10</td>\n",
       "      <td>19500000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                Name                  Team Position   Birthday    Salary\n",
       "248   Zylan Cheatham  New Orleans Pelicans       SF 1995-11-17     79568\n",
       "137  Zion Williamson  New Orleans Pelicans        F 2000-07-06   9757440\n",
       "312     Zhaire Smith    Philadelphia 76ers       SG 1999-06-04   3058800\n",
       "302     Zach Norvell    Los Angeles Lakers       SG 1997-12-09     79568\n",
       "159      Zach LaVine         Chicago Bulls       PG 1995-03-10  19500000"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按照字母表顺序逆序排序\n",
    "nba.sort_values(by='Name', ascending=False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>136</th>\n",
       "      <td>Sekou Doumbouya</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>SF</td>\n",
       "      <td>2000-12-23</td>\n",
       "      <td>3285120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>432</th>\n",
       "      <td>Talen Horton-Tucker</td>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>GF</td>\n",
       "      <td>2000-11-25</td>\n",
       "      <td>898310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>Zion Williamson</td>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>F</td>\n",
       "      <td>2000-07-06</td>\n",
       "      <td>9757440</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>313</th>\n",
       "      <td>RJ Barrett</td>\n",
       "      <td>New York Knicks</td>\n",
       "      <td>SG</td>\n",
       "      <td>2000-06-14</td>\n",
       "      <td>7839960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>392</th>\n",
       "      <td>Jalen Lecque</td>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>G</td>\n",
       "      <td>2000-06-13</td>\n",
       "      <td>898310</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    Name                  Team Position   Birthday   Salary\n",
       "136      Sekou Doumbouya       Detroit Pistons       SF 2000-12-23  3285120\n",
       "432  Talen Horton-Tucker    Los Angeles Lakers       GF 2000-11-25   898310\n",
       "137      Zion Williamson  New Orleans Pelicans        F 2000-07-06  9757440\n",
       "313           RJ Barrett       New York Knicks       SG 2000-06-14  7839960\n",
       "392         Jalen Lecque          Phoenix Suns        G 2000-06-13   898310"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 不使用 nsmallest 方法情况下，找到 nba 数据集中最年轻的5名球员\n",
    "nba.sort_values(by=\"Birthday\",ascending=False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>359</th>\n",
       "      <td>Alex Len</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>C</td>\n",
       "      <td>1993-06-16</td>\n",
       "      <td>4160000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>167</th>\n",
       "      <td>Allen Crabbe</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>SG</td>\n",
       "      <td>1992-04-09</td>\n",
       "      <td>18500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>276</th>\n",
       "      <td>Brandon Goodwin</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>PG</td>\n",
       "      <td>1995-10-02</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>438</th>\n",
       "      <td>Bruno Fernando</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>C</td>\n",
       "      <td>1998-08-15</td>\n",
       "      <td>1400000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>194</th>\n",
       "      <td>Cam Reddish</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>SF</td>\n",
       "      <td>1999-09-01</td>\n",
       "      <td>4245720</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>418</th>\n",
       "      <td>Jordan McRae</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PG</td>\n",
       "      <td>1991-03-28</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>273</th>\n",
       "      <td>Justin Robinson</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PG</td>\n",
       "      <td>1997-10-12</td>\n",
       "      <td>898310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>428</th>\n",
       "      <td>Moritz Wagner</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>C</td>\n",
       "      <td>1997-04-26</td>\n",
       "      <td>2063520</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>Rui Hachimura</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-02-08</td>\n",
       "      <td>4469160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>Thomas Bryant</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>C</td>\n",
       "      <td>1997-07-31</td>\n",
       "      <td>8000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                Name                Team Position   Birthday    Salary\n",
       "359         Alex Len       Atlanta Hawks        C 1993-06-16   4160000\n",
       "167     Allen Crabbe       Atlanta Hawks       SG 1992-04-09  18500000\n",
       "276  Brandon Goodwin       Atlanta Hawks       PG 1995-10-02     79568\n",
       "438   Bruno Fernando       Atlanta Hawks        C 1998-08-15   1400000\n",
       "194      Cam Reddish       Atlanta Hawks       SF 1999-09-01   4245720\n",
       "..               ...                 ...      ...        ...       ...\n",
       "418     Jordan McRae  Washington Wizards       PG 1991-03-28   1645357\n",
       "273  Justin Robinson  Washington Wizards       PG 1997-10-12    898310\n",
       "428    Moritz Wagner  Washington Wizards        C 1997-04-26   2063520\n",
       "21     Rui Hachimura  Washington Wizards       PF 1998-02-08   4469160\n",
       "36     Thomas Bryant  Washington Wizards        C 1997-07-31   8000000\n",
       "\n",
       "[450 rows x 5 columns]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按照多列进行排序， 将列表传递给 sort_values 方法的 by 参数来对 DataFrame 中的多列进行排序\n",
    "# 首先按 Team 列，然后按 name 列。 Pandas 默认对所有列进行升序排序\n",
    "nba.sort_values(by=['Team','Name'])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>Thomas Bryant</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>C</td>\n",
       "      <td>1997-07-31</td>\n",
       "      <td>8000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>Rui Hachimura</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-02-08</td>\n",
       "      <td>4469160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>428</th>\n",
       "      <td>Moritz Wagner</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>C</td>\n",
       "      <td>1997-04-26</td>\n",
       "      <td>2063520</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>273</th>\n",
       "      <td>Justin Robinson</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PG</td>\n",
       "      <td>1997-10-12</td>\n",
       "      <td>898310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>418</th>\n",
       "      <td>Jordan McRae</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PG</td>\n",
       "      <td>1991-03-28</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>194</th>\n",
       "      <td>Cam Reddish</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>SF</td>\n",
       "      <td>1999-09-01</td>\n",
       "      <td>4245720</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>438</th>\n",
       "      <td>Bruno Fernando</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>C</td>\n",
       "      <td>1998-08-15</td>\n",
       "      <td>1400000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>276</th>\n",
       "      <td>Brandon Goodwin</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>PG</td>\n",
       "      <td>1995-10-02</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>167</th>\n",
       "      <td>Allen Crabbe</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>SG</td>\n",
       "      <td>1992-04-09</td>\n",
       "      <td>18500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>359</th>\n",
       "      <td>Alex Len</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>C</td>\n",
       "      <td>1993-06-16</td>\n",
       "      <td>4160000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                Name                Team Position   Birthday    Salary\n",
       "36     Thomas Bryant  Washington Wizards        C 1997-07-31   8000000\n",
       "21     Rui Hachimura  Washington Wizards       PF 1998-02-08   4469160\n",
       "428    Moritz Wagner  Washington Wizards        C 1997-04-26   2063520\n",
       "273  Justin Robinson  Washington Wizards       PG 1997-10-12    898310\n",
       "418     Jordan McRae  Washington Wizards       PG 1991-03-28   1645357\n",
       "..               ...                 ...      ...        ...       ...\n",
       "194      Cam Reddish       Atlanta Hawks       SF 1999-09-01   4245720\n",
       "438   Bruno Fernando       Atlanta Hawks        C 1998-08-15   1400000\n",
       "276  Brandon Goodwin       Atlanta Hawks       PG 1995-10-02     79568\n",
       "167     Allen Crabbe       Atlanta Hawks       SG 1992-04-09  18500000\n",
       "359         Alex Len       Atlanta Hawks        C 1993-06-16   4160000\n",
       "\n",
       "[450 rows x 5 columns]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过 ascending 参数降序排序\n",
    "nba.sort_values(by=['Team','Name'], ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>399</th>\n",
       "      <td>Admiral Schofield</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>SF</td>\n",
       "      <td>1997-03-30</td>\n",
       "      <td>1000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>Bradley Beal</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>SG</td>\n",
       "      <td>1993-06-28</td>\n",
       "      <td>27093018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>353</th>\n",
       "      <td>Chris Chiozza</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PG</td>\n",
       "      <td>1995-11-21</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>226</th>\n",
       "      <td>Davis Bertans</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PF</td>\n",
       "      <td>1992-11-12</td>\n",
       "      <td>7000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>283</th>\n",
       "      <td>Garrison Mathews</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-10-24</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>339</th>\n",
       "      <td>Jabari Parker</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-03-15</td>\n",
       "      <td>6500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>John Collins</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>PF</td>\n",
       "      <td>1997-09-23</td>\n",
       "      <td>2686560</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>Kevin Huerter</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>SG</td>\n",
       "      <td>1998-08-27</td>\n",
       "      <td>2636280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>290</th>\n",
       "      <td>Tyrone Wallace</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>PG</td>\n",
       "      <td>1994-06-10</td>\n",
       "      <td>1620564</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>Vince Carter</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>PF</td>\n",
       "      <td>1977-01-26</td>\n",
       "      <td>2564753</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Name                Team Position   Birthday    Salary\n",
       "399  Admiral Schofield  Washington Wizards       SF 1997-03-30   1000000\n",
       "35        Bradley Beal  Washington Wizards       SG 1993-06-28  27093018\n",
       "353      Chris Chiozza  Washington Wizards       PG 1995-11-21     79568\n",
       "226      Davis Bertans  Washington Wizards       PF 1992-11-12   7000000\n",
       "283   Garrison Mathews  Washington Wizards       SG 1996-10-24     79568\n",
       "..                 ...                 ...      ...        ...       ...\n",
       "339      Jabari Parker       Atlanta Hawks       PF 1995-03-15   6500000\n",
       "84        John Collins       Atlanta Hawks       PF 1997-09-23   2686560\n",
       "20       Kevin Huerter       Atlanta Hawks       SG 1998-08-27   2636280\n",
       "290     Tyrone Wallace       Atlanta Hawks       PG 1994-06-10   1620564\n",
       "98        Vince Carter       Atlanta Hawks       PF 1977-01-26   2564753\n",
       "\n",
       "[450 rows x 5 columns]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ascending 传递布尔值列表，对每个字段进行不同的排序\n",
    "nba.sort_values(by=['Team',\"Name\"],ascending=[False,True])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 得到了预期的结果，可以让排序持久化\n",
    "nba = nba.sort_values(by=['Team',\"Name\"],ascending=[False,True])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 4.4 按照索引排序\n",
    "# 经过永久花排序，DataFrame 的数据顺序与原始顺序不一致\n",
    "# 怎么才能恢复到原来的样子\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Shake Milton</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Christian Wood</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>PJ Washington</td>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Derrick Rose</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Marial Shayok</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             Name                Team Position   Birthday   Salary\n",
       "0    Shake Milton  Philadelphia 76ers       SG 1996-09-26  1445697\n",
       "1  Christian Wood     Detroit Pistons       PF 1995-09-27  1645357\n",
       "2   PJ Washington   Charlotte Hornets       PF 1998-08-23  3831840\n",
       "3    Derrick Rose     Detroit Pistons       PG 1988-10-04  7317074\n",
       "4   Marial Shayok  Philadelphia 76ers        G 1995-07-26    79568"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#按照索引进行排序\n",
    "# 按照索引位置，而不是按列值对数据集进行排序，就可以恢复到原始排序顺序\n",
    "nba.sort_index().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>449</th>\n",
       "      <td>Ricky Rubio</td>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-10-21</td>\n",
       "      <td>16200000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>448</th>\n",
       "      <td>Collin Sexton</td>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1999-01-04</td>\n",
       "      <td>4764960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>447</th>\n",
       "      <td>Robin Lopez</td>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>4767000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>446</th>\n",
       "      <td>Harry Giles</td>\n",
       "      <td>Sacramento Kings</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-04-22</td>\n",
       "      <td>2578800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>445</th>\n",
       "      <td>Austin Rivers</td>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1992-08-01</td>\n",
       "      <td>2174310</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Name                 Team Position   Birthday    Salary\n",
       "449    Ricky Rubio         Phoenix Suns       PG 1990-10-21  16200000\n",
       "448  Collin Sexton  Cleveland Cavaliers       PG 1999-01-04   4764960\n",
       "447    Robin Lopez      Milwaukee Bucks        C 1988-04-01   4767000\n",
       "446    Harry Giles     Sacramento Kings       PF 1998-04-22   2578800\n",
       "445  Austin Rivers      Houston Rockets       PG 1992-08-01   2174310"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过 ascending 进行排序翻转\n",
    "nba.sort_index(ascending=False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 索引恢复\n",
    "nba = nba.sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Name</th>\n",
       "      <th>Position</th>\n",
       "      <th>Salary</th>\n",
       "      <th>Team</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>Shake Milton</td>\n",
       "      <td>SG</td>\n",
       "      <td>1445697</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>Christian Wood</td>\n",
       "      <td>PF</td>\n",
       "      <td>1645357</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>PJ Washington</td>\n",
       "      <td>PF</td>\n",
       "      <td>3831840</td>\n",
       "      <td>Charlotte Hornets</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>Derrick Rose</td>\n",
       "      <td>PG</td>\n",
       "      <td>7317074</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>Marial Shayok</td>\n",
       "      <td>G</td>\n",
       "      <td>79568</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Birthday            Name Position   Salary                Team\n",
       "0 1996-09-26    Shake Milton       SG  1445697  Philadelphia 76ers\n",
       "1 1995-09-27  Christian Wood       PF  1645357     Detroit Pistons\n",
       "2 1998-08-23   PJ Washington       PF  3831840   Charlotte Hornets\n",
       "3 1988-10-04    Derrick Rose       PG  7317074     Detroit Pistons\n",
       "4 1995-07-26   Marial Shayok        G    79568  Philadelphia 76ers"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4.4.2 按照列索引进行排序\n",
    "# DataFrame 是一种二位数据结构。可以排序一个额外的轴：垂直轴\n",
    "# 对 DataFrame 的列进行排序，可以使用 sort_index 方法，但是需要添加一个 axis 参数，并为它设定 columbs 或1 的值\n",
    "nba.sort_index(axis=\"columns\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Salary</th>\n",
       "      <th>Position</th>\n",
       "      <th>Name</th>\n",
       "      <th>Birthday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>1445697</td>\n",
       "      <td>SG</td>\n",
       "      <td>Shake Milton</td>\n",
       "      <td>1996-09-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>1645357</td>\n",
       "      <td>PF</td>\n",
       "      <td>Christian Wood</td>\n",
       "      <td>1995-09-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>3831840</td>\n",
       "      <td>PF</td>\n",
       "      <td>PJ Washington</td>\n",
       "      <td>1998-08-23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>7317074</td>\n",
       "      <td>PG</td>\n",
       "      <td>Derrick Rose</td>\n",
       "      <td>1988-10-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>79568</td>\n",
       "      <td>G</td>\n",
       "      <td>Marial Shayok</td>\n",
       "      <td>1995-07-26</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 Team   Salary Position            Name   Birthday\n",
       "0  Philadelphia 76ers  1445697       SG    Shake Milton 1996-09-26\n",
       "1     Detroit Pistons  1645357       PF  Christian Wood 1995-09-27\n",
       "2   Charlotte Hornets  3831840       PF   PJ Washington 1998-08-23\n",
       "3     Detroit Pistons  7317074       PG    Derrick Rose 1988-10-04\n",
       "4  Philadelphia 76ers    79568        G   Marial Shayok 1995-07-26"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 以字母表的逆序对列进行排序，可以使用 ascending 参数\n",
    "nba.sort_index(axis=\"columns\", ascending=False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christian Wood</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derrick Rose</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marial Shayok</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Austin Rivers</th>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1992-08-01</td>\n",
       "      <td>2174310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Harry Giles</th>\n",
       "      <td>Sacramento Kings</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-04-22</td>\n",
       "      <td>2578800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Robin Lopez</th>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>4767000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Collin Sexton</th>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1999-01-04</td>\n",
       "      <td>4764960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ricky Rubio</th>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-10-21</td>\n",
       "      <td>16200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Team Position   Birthday    Salary\n",
       "Name                                                             \n",
       "Shake Milton     Philadelphia 76ers       SG 1996-09-26   1445697\n",
       "Christian Wood      Detroit Pistons       PF 1995-09-27   1645357\n",
       "PJ Washington     Charlotte Hornets       PF 1998-08-23   3831840\n",
       "Derrick Rose        Detroit Pistons       PG 1988-10-04   7317074\n",
       "Marial Shayok    Philadelphia 76ers        G 1995-07-26     79568\n",
       "...                             ...      ...        ...       ...\n",
       "Austin Rivers       Houston Rockets       PG 1992-08-01   2174310\n",
       "Harry Giles        Sacramento Kings       PF 1998-04-22   2578800\n",
       "Robin Lopez         Milwaukee Bucks        C 1988-04-01   4767000\n",
       "Collin Sexton   Cleveland Cavaliers       PG 1999-01-04   4764960\n",
       "Ricky Rubio            Phoenix Suns       PG 1990-10-21  16200000\n",
       "\n",
       "[450 rows x 4 columns]"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4.5 设置新的索引\n",
    "# 使用 name 列的值作为 nba DataFrame 的索引\n",
    "nba.set_index(keys=\"Name\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christian Wood</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derrick Rose</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marial Shayok</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Austin Rivers</th>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1992-08-01</td>\n",
       "      <td>2174310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Harry Giles</th>\n",
       "      <td>Sacramento Kings</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-04-22</td>\n",
       "      <td>2578800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Robin Lopez</th>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>4767000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Collin Sexton</th>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1999-01-04</td>\n",
       "      <td>4764960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ricky Rubio</th>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-10-21</td>\n",
       "      <td>16200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Team Position   Birthday    Salary\n",
       "Name                                                             \n",
       "Shake Milton     Philadelphia 76ers       SG 1996-09-26   1445697\n",
       "Christian Wood      Detroit Pistons       PF 1995-09-27   1645357\n",
       "PJ Washington     Charlotte Hornets       PF 1998-08-23   3831840\n",
       "Derrick Rose        Detroit Pistons       PG 1988-10-04   7317074\n",
       "Marial Shayok    Philadelphia 76ers        G 1995-07-26     79568\n",
       "...                             ...      ...        ...       ...\n",
       "Austin Rivers       Houston Rockets       PG 1992-08-01   2174310\n",
       "Harry Giles        Sacramento Kings       PF 1998-04-22   2578800\n",
       "Robin Lopez         Milwaukee Bucks        C 1988-04-01   4767000\n",
       "Collin Sexton   Cleveland Cavaliers       PG 1999-01-04   4764960\n",
       "Ricky Rubio            Phoenix Suns       PG 1990-10-21  16200000\n",
       "\n",
       "[450 rows x 4 columns]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 在 csv 导入时，通过参数 index_col 设置索引\n",
    "\n",
    "nba = pd.read_csv('./file/chapter_04/nba.csv', parse_dates=[\"Birthday\"], date_format={\"Birthday\": 'mixed'}, index_col=\"Name\")\n",
    "nba"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 4.6 从 DataFra,e 中选择列\n",
    "# DataFrame 是具有公共索引的 Series 对象的集合，有多种语法选项可用于从 DataFrame 中提取一个或多个 Series\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name\n",
       "Shake Milton       1445697\n",
       "Christian Wood     1645357\n",
       "PJ Washington      3831840\n",
       "Derrick Rose       7317074\n",
       "Marial Shayok        79568\n",
       "                    ...   \n",
       "Austin Rivers      2174310\n",
       "Harry Giles        2578800\n",
       "Robin Lopez        4767000\n",
       "Collin Sexton      4764960\n",
       "Ricky Rubio       16200000\n",
       "Name: Salary, Length: 450, dtype: int64"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 从 DataFrame 中选择单列\n",
    "nba.Salary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name\n",
       "Shake Milton      SG\n",
       "Christian Wood    PF\n",
       "PJ Washington     PF\n",
       "Derrick Rose      PG\n",
       "Marial Shayok      G\n",
       "                  ..\n",
       "Austin Rivers     PG\n",
       "Harry Giles       PF\n",
       "Robin Lopez        C\n",
       "Collin Sexton     PG\n",
       "Ricky Rubio       PG\n",
       "Name: Position, Length: 450, dtype: object"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过 DataFrame 后面的方括号设置列名来提取一列\n",
    "# 这种方式优点是支持带空格的列名\n",
    "nba['Position']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Salary</th>\n",
       "      <th>Birthday</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>1445697</td>\n",
       "      <td>1996-09-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christian Wood</th>\n",
       "      <td>1645357</td>\n",
       "      <td>1995-09-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>3831840</td>\n",
       "      <td>1998-08-23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derrick Rose</th>\n",
       "      <td>7317074</td>\n",
       "      <td>1988-10-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marial Shayok</th>\n",
       "      <td>79568</td>\n",
       "      <td>1995-07-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Austin Rivers</th>\n",
       "      <td>2174310</td>\n",
       "      <td>1992-08-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Harry Giles</th>\n",
       "      <td>2578800</td>\n",
       "      <td>1998-04-22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Robin Lopez</th>\n",
       "      <td>4767000</td>\n",
       "      <td>1988-04-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Collin Sexton</th>\n",
       "      <td>4764960</td>\n",
       "      <td>1999-01-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ricky Rubio</th>\n",
       "      <td>16200000</td>\n",
       "      <td>1990-10-21</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Salary   Birthday\n",
       "Name                               \n",
       "Shake Milton     1445697 1996-09-26\n",
       "Christian Wood   1645357 1995-09-27\n",
       "PJ Washington    3831840 1998-08-23\n",
       "Derrick Rose     7317074 1988-10-04\n",
       "Marial Shayok      79568 1995-07-26\n",
       "...                  ...        ...\n",
       "Austin Rivers    2174310 1992-08-01\n",
       "Harry Giles      2578800 1998-04-22\n",
       "Robin Lopez      4767000 1988-04-01\n",
       "Collin Sexton    4764960 1999-01-04\n",
       "Ricky Rubio     16200000 1990-10-21\n",
       "\n",
       "[450 rows x 2 columns]"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 从DataFrame 中提取多列, 传入列名称列表来实现\n",
    "nba[['Salary','Birthday']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christian Wood</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derrick Rose</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marial Shayok</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Austin Rivers</th>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>PG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Harry Giles</th>\n",
       "      <td>Sacramento Kings</td>\n",
       "      <td>PF</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Robin Lopez</th>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Collin Sexton</th>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ricky Rubio</th>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Team Position\n",
       "Name                                        \n",
       "Shake Milton     Philadelphia 76ers       SG\n",
       "Christian Wood      Detroit Pistons       PF\n",
       "PJ Washington     Charlotte Hornets       PF\n",
       "Derrick Rose        Detroit Pistons       PG\n",
       "Marial Shayok    Philadelphia 76ers        G\n",
       "...                             ...      ...\n",
       "Austin Rivers       Houston Rockets       PG\n",
       "Harry Giles        Sacramento Kings       PF\n",
       "Robin Lopez         Milwaukee Bucks        C\n",
       "Collin Sexton   Cleveland Cavaliers       PG\n",
       "Ricky Rubio            Phoenix Suns       PG\n",
       "\n",
       "[450 rows x 2 columns]"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# select_dtyes 方法格努数据类型选择列，该方法接受两个参数 include 和 exclude\n",
    "# 从 nba 中选择字符串类型的列\n",
    "nba.select_dtypes(include=\"object\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Birthday</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>1996-09-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christian Wood</th>\n",
       "      <td>1995-09-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>1998-08-23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derrick Rose</th>\n",
       "      <td>1988-10-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marial Shayok</th>\n",
       "      <td>1995-07-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Austin Rivers</th>\n",
       "      <td>1992-08-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Harry Giles</th>\n",
       "      <td>1998-04-22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Robin Lopez</th>\n",
       "      <td>1988-04-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Collin Sexton</th>\n",
       "      <td>1999-01-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ricky Rubio</th>\n",
       "      <td>1990-10-21</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                 Birthday\n",
       "Name                     \n",
       "Shake Milton   1996-09-26\n",
       "Christian Wood 1995-09-27\n",
       "PJ Washington  1998-08-23\n",
       "Derrick Rose   1988-10-04\n",
       "Marial Shayok  1995-07-26\n",
       "...                   ...\n",
       "Austin Rivers  1992-08-01\n",
       "Harry Giles    1998-04-22\n",
       "Robin Lopez    1988-04-01\n",
       "Collin Sexton  1999-01-04\n",
       "Ricky Rubio    1990-10-21\n",
       "\n",
       "[450 rows x 1 columns]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选择除字符串和整数列之外的所有列\n",
    "nba.select_dtypes(exclude=['object','int'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 4.7 从DataFrame 中选择行\n",
    "# 如何通过索引标签或索引位置提取 DataFrame 的行\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Team         Los Angeles Lakers\n",
       "Position                     PF\n",
       "Birthday    1984-12-30 00:00:00\n",
       "Salary                 37436858\n",
       "Name: LeBron James, dtype: object"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用索引标签提取行\n",
    "# loc 属性按标签提取一行，返回 Series 的值。loc 的属性称为访问器，是因为他们访问的是一段数据，在Loc 之后立即键入一对方括号并传入目标索引标签\n",
    "nba.loc[\"LeBron James\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Kawhi Leonard</th>\n",
       "      <td>Los Angeles Clippers</td>\n",
       "      <td>SF</td>\n",
       "      <td>1991-06-29</td>\n",
       "      <td>32742000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Paul George</th>\n",
       "      <td>Los Angeles Clippers</td>\n",
       "      <td>SF</td>\n",
       "      <td>1990-05-02</td>\n",
       "      <td>33005556</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Team Position   Birthday    Salary\n",
       "Name                                                             \n",
       "Kawhi Leonard  Los Angeles Clippers       SF 1991-06-29  32742000\n",
       "Paul George    Los Angeles Clippers       SF 1990-05-02  33005556"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 在方括号内传递一个列表可以提取多行 , pandas 将数据存储在 DataFrame 中\n",
    "nba.loc[['Kawhi Leonard','Paul George']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Otto Porter</th>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>SF</td>\n",
       "      <td>1993-06-03</td>\n",
       "      <td>27250576</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Dozier</th>\n",
       "      <td>Denver Nuggets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1996-10-25</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pascal Siakam</th>\n",
       "      <td>Toronto Raptors</td>\n",
       "      <td>PF</td>\n",
       "      <td>1994-04-02</td>\n",
       "      <td>2351838</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pat Connaughton</th>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>SG</td>\n",
       "      <td>1993-01-06</td>\n",
       "      <td>1723050</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Patrick Beverley</th>\n",
       "      <td>Los Angeles Clippers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-07-12</td>\n",
       "      <td>12345680</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                  Team Position   Birthday    Salary\n",
       "Name                                                                \n",
       "Otto Porter              Chicago Bulls       SF 1993-06-03  27250576\n",
       "PJ Dozier               Denver Nuggets       PG 1996-10-25     79568\n",
       "PJ Washington        Charlotte Hornets       PF 1998-08-23   3831840\n",
       "Pascal Siakam          Toronto Raptors       PF 1994-04-02   2351838\n",
       "Pat Connaughton        Milwaukee Bucks       SG 1993-01-06   1723050\n",
       "Patrick Beverley  Los Angeles Clippers       PG 1988-07-12  12345680"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# loc 可以用来提取一系列索引标签。提取 Otto Porter 和 Patrick Beverley 之间的所有请求\n",
    "# 支持列表切片语法。Otto Porter 代表下限，Patrick Beverley代表上限·\n",
    "nba.sort_index().loc[\"Otto Porter\":'Patrick Beverley']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Zach Collins</th>\n",
       "      <td>Portland Trail Blazers</td>\n",
       "      <td>C</td>\n",
       "      <td>1997-11-19</td>\n",
       "      <td>4240200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach LaVine</th>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>PG</td>\n",
       "      <td>1995-03-10</td>\n",
       "      <td>19500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach Norvell</th>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1997-12-09</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zhaire Smith</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1999-06-04</td>\n",
       "      <td>3058800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zion Williamson</th>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>F</td>\n",
       "      <td>2000-07-06</td>\n",
       "      <td>9757440</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zylan Cheatham</th>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>SF</td>\n",
       "      <td>1995-11-17</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   Team Position   Birthday    Salary\n",
       "Name                                                                 \n",
       "Zach Collins     Portland Trail Blazers        C 1997-11-19   4240200\n",
       "Zach LaVine               Chicago Bulls       PG 1995-03-10  19500000\n",
       "Zach Norvell         Los Angeles Lakers       SG 1997-12-09     79568\n",
       "Zhaire Smith         Philadelphia 76ers       SG 1999-06-04   3058800\n",
       "Zion Williamson    New Orleans Pelicans        F 2000-07-06   9757440\n",
       "Zylan Cheatham     New Orleans Pelicans       SF 1995-11-17     79568"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# loc 从 DataFrame 从中间拉到末尾\n",
    "nba.sort_index().loc['Zach Collins':]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Aaron Gordon</th>\n",
       "      <td>Orlando Magic</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-16</td>\n",
       "      <td>19863636</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aaron Holiday</th>\n",
       "      <td>Indiana Pacers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1996-09-30</td>\n",
       "      <td>2239200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Abdel Nader</th>\n",
       "      <td>Oklahoma City Thunder</td>\n",
       "      <td>SF</td>\n",
       "      <td>1993-09-25</td>\n",
       "      <td>1618520</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Adam Mokoka</th>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>G</td>\n",
       "      <td>1998-07-18</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Admiral Schofield</th>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>SF</td>\n",
       "      <td>1997-03-30</td>\n",
       "      <td>1000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Al Horford</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>C</td>\n",
       "      <td>1986-06-03</td>\n",
       "      <td>28000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    Team Position   Birthday    Salary\n",
       "Name                                                                  \n",
       "Aaron Gordon               Orlando Magic       PF 1995-09-16  19863636\n",
       "Aaron Holiday             Indiana Pacers       PG 1996-09-30   2239200\n",
       "Abdel Nader        Oklahoma City Thunder       SF 1993-09-25   1618520\n",
       "Adam Mokoka                Chicago Bulls        G 1998-07-18     79568\n",
       "Admiral Schofield     Washington Wizards       SF 1997-03-30   1000000\n",
       "Al Horford            Philadelphia 76ers        C 1986-06-03  28000000"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# loc 切片，从 DataFrame 从开头拉到特定的索引标签\n",
    "nba.sort_index().loc[:'Al Horford']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'Bugs Bunny'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "File \u001b[1;32mc:\\Miniconda3\\lib\\site-packages\\pandas\\core\\indexes\\base.py:3653\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   3652\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m-> 3653\u001b[0m     \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_engine\u001b[39m.\u001b[39;49mget_loc(casted_key)\n\u001b[0;32m   3654\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mKeyError\u001b[39;00m \u001b[39mas\u001b[39;00m err:\n",
      "File \u001b[1;32mc:\\Miniconda3\\lib\\site-packages\\pandas\\_libs\\index.pyx:147\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32mc:\\Miniconda3\\lib\\site-packages\\pandas\\_libs\\index.pyx:176\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi:7080\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi:7088\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: 'Bugs Bunny'",
      "\nThe above exception was the direct cause of the following exception:\n",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[57], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# DataFrame 中不存在所设置的索引标签，引发异常\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[43mnba\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mloc\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mBugs Bunny\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\n",
      "File \u001b[1;32mc:\\Miniconda3\\lib\\site-packages\\pandas\\core\\indexing.py:1103\u001b[0m, in \u001b[0;36m_LocationIndexer.__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   1100\u001b[0m axis \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39maxis \u001b[39mor\u001b[39;00m \u001b[39m0\u001b[39m\n\u001b[0;32m   1102\u001b[0m maybe_callable \u001b[39m=\u001b[39m com\u001b[39m.\u001b[39mapply_if_callable(key, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mobj)\n\u001b[1;32m-> 1103\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_getitem_axis(maybe_callable, axis\u001b[39m=\u001b[39;49maxis)\n",
      "File \u001b[1;32mc:\\Miniconda3\\lib\\site-packages\\pandas\\core\\indexing.py:1343\u001b[0m, in \u001b[0;36m_LocIndexer._getitem_axis\u001b[1;34m(self, key, axis)\u001b[0m\n\u001b[0;32m   1341\u001b[0m \u001b[39m# fall thru to straight lookup\u001b[39;00m\n\u001b[0;32m   1342\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_validate_key(key, axis)\n\u001b[1;32m-> 1343\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_get_label(key, axis\u001b[39m=\u001b[39;49maxis)\n",
      "File \u001b[1;32mc:\\Miniconda3\\lib\\site-packages\\pandas\\core\\indexing.py:1293\u001b[0m, in \u001b[0;36m_LocIndexer._get_label\u001b[1;34m(self, label, axis)\u001b[0m\n\u001b[0;32m   1291\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_get_label\u001b[39m(\u001b[39mself\u001b[39m, label, axis: AxisInt):\n\u001b[0;32m   1292\u001b[0m     \u001b[39m# GH#5567 this will fail if the label is not present in the axis.\u001b[39;00m\n\u001b[1;32m-> 1293\u001b[0m     \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mobj\u001b[39m.\u001b[39;49mxs(label, axis\u001b[39m=\u001b[39;49maxis)\n",
      "File \u001b[1;32mc:\\Miniconda3\\lib\\site-packages\\pandas\\core\\generic.py:4095\u001b[0m, in \u001b[0;36mNDFrame.xs\u001b[1;34m(self, key, axis, level, drop_level)\u001b[0m\n\u001b[0;32m   4093\u001b[0m             new_index \u001b[39m=\u001b[39m index[loc]\n\u001b[0;32m   4094\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m-> 4095\u001b[0m     loc \u001b[39m=\u001b[39m index\u001b[39m.\u001b[39;49mget_loc(key)\n\u001b[0;32m   4097\u001b[0m     \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(loc, np\u001b[39m.\u001b[39mndarray):\n\u001b[0;32m   4098\u001b[0m         \u001b[39mif\u001b[39;00m loc\u001b[39m.\u001b[39mdtype \u001b[39m==\u001b[39m np\u001b[39m.\u001b[39mbool_:\n",
      "File \u001b[1;32mc:\\Miniconda3\\lib\\site-packages\\pandas\\core\\indexes\\base.py:3655\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   3653\u001b[0m     \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_engine\u001b[39m.\u001b[39mget_loc(casted_key)\n\u001b[0;32m   3654\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mKeyError\u001b[39;00m \u001b[39mas\u001b[39;00m err:\n\u001b[1;32m-> 3655\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mKeyError\u001b[39;00m(key) \u001b[39mfrom\u001b[39;00m \u001b[39merr\u001b[39;00m\n\u001b[0;32m   3656\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mTypeError\u001b[39;00m:\n\u001b[0;32m   3657\u001b[0m     \u001b[39m# If we have a listlike key, _check_indexing_error will raise\u001b[39;00m\n\u001b[0;32m   3658\u001b[0m     \u001b[39m#  InvalidIndexError. Otherwise we fall through and re-raise\u001b[39;00m\n\u001b[0;32m   3659\u001b[0m     \u001b[39m#  the TypeError.\u001b[39;00m\n\u001b[0;32m   3660\u001b[0m     \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_check_indexing_error(key)\n",
      "\u001b[1;31mKeyError\u001b[0m: 'Bugs Bunny'"
     ]
    }
   ],
   "source": [
    "# DataFrame 中不存在所设置的索引标签，引发异常\n",
    "nba.loc['Bugs Bunny']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Team             Denver Nuggets\n",
       "Position                     PF\n",
       "Birthday    1999-04-03 00:00:00\n",
       "Salary                  1416852\n",
       "Name: Jarred Vanderbilt, dtype: object"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按索引位置提取行\n",
    "# iloc (index loction) 访问器可以按索引位置提取行，与 loc 类似\n",
    "nba.iloc[300]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Brian Bowen</th>\n",
       "      <td>Indiana Pacers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1998-10-02</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marco Belinelli</th>\n",
       "      <td>San Antonio Spurs</td>\n",
       "      <td>SF</td>\n",
       "      <td>1986-03-25</td>\n",
       "      <td>5846154</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jarred Vanderbilt</th>\n",
       "      <td>Denver Nuggets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1999-04-03</td>\n",
       "      <td>1416852</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Louis King</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>F</td>\n",
       "      <td>1999-04-06</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                Team Position   Birthday   Salary\n",
       "Name                                                             \n",
       "Brian Bowen           Indiana Pacers       SG 1998-10-02    79568\n",
       "Marco Belinelli    San Antonio Spurs       SF 1986-03-25  5846154\n",
       "Jarred Vanderbilt     Denver Nuggets       PF 1999-04-03  1416852\n",
       "Louis King           Detroit Pistons        F 1999-04-06    79568"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# iloc 支持通过索引列表来定位多条记录\n",
    "nba.iloc[[100,200,300,400]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Louis King</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>F</td>\n",
       "      <td>1999-04-06</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kostas Antetokounmpo</th>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>PF</td>\n",
       "      <td>1997-11-20</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Rodions Kurucs</th>\n",
       "      <td>Brooklyn Nets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-02-05</td>\n",
       "      <td>1699236</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spencer Dinwiddie</th>\n",
       "      <td>Brooklyn Nets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1993-04-06</td>\n",
       "      <td>10605600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    Team Position   Birthday    Salary\n",
       "Name                                                                  \n",
       "Louis King               Detroit Pistons        F 1999-04-06     79568\n",
       "Kostas Antetokounmpo  Los Angeles Lakers       PF 1997-11-20     79568\n",
       "Rodions Kurucs             Brooklyn Nets       PF 1998-02-05   1699236\n",
       "Spencer Dinwiddie          Brooklyn Nets       PG 1993-04-06  10605600"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表切片语法\n",
    "nba.iloc[400:404]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christian Wood</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                              Team Position   Birthday   Salary\n",
       "Name                                                           \n",
       "Shake Milton    Philadelphia 76ers       SG 1996-09-26  1445697\n",
       "Christian Wood     Detroit Pistons       PF 1995-09-27  1645357"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 从头开始提取数据\n",
    "nba.iloc[:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Robin Lopez</th>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>4767000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Collin Sexton</th>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1999-01-04</td>\n",
       "      <td>4764960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ricky Rubio</th>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-10-21</td>\n",
       "      <td>16200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                              Team Position   Birthday    Salary\n",
       "Name                                                            \n",
       "Robin Lopez        Milwaukee Bucks        C 1988-04-01   4767000\n",
       "Collin Sexton  Cleveland Cavaliers       PG 1999-01-04   4764960\n",
       "Ricky Rubio           Phoenix Suns       PG 1990-10-21  16200000"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 提取到尾的数据\n",
    "nba.iloc[447:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Jared Dudley</th>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>PF</td>\n",
       "      <td>1985-07-10</td>\n",
       "      <td>2564753</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Max Strus</th>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-03-28</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kevon Looney</th>\n",
       "      <td>Golden State Warriors</td>\n",
       "      <td>C</td>\n",
       "      <td>1996-02-06</td>\n",
       "      <td>4464286</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Willy Hernangomez</th>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>C</td>\n",
       "      <td>1994-05-27</td>\n",
       "      <td>1557250</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    Team Position   Birthday   Salary\n",
       "Name                                                                 \n",
       "Jared Dudley          Los Angeles Lakers       PF 1985-07-10  2564753\n",
       "Max Strus                  Chicago Bulls       SG 1996-03-28    79568\n",
       "Kevon Looney       Golden State Warriors        C 1996-02-06  4464286\n",
       "Willy Hernangomez      Charlotte Hornets        C 1994-05-27  1557250"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 提取倒数10行到倒数6行的数据\n",
    "nba.iloc[-10:-6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marial Shayok</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kendrick Nunn</th>\n",
       "      <td>Miami Heat</td>\n",
       "      <td>SG</td>\n",
       "      <td>1995-08-03</td>\n",
       "      <td>1416852</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Brook Lopez</th>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>12093024</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             Team Position   Birthday    Salary\n",
       "Name                                                           \n",
       "Shake Milton   Philadelphia 76ers       SG 1996-09-26   1445697\n",
       "PJ Washington   Charlotte Hornets       PF 1998-08-23   3831840\n",
       "Marial Shayok  Philadelphia 76ers        G 1995-07-26     79568\n",
       "Kendrick Nunn          Miami Heat       SG 1995-08-03   1416852\n",
       "Brook Lopez       Milwaukee Bucks        C 1988-04-01  12093024"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 方括号内提供的第三个数字可以用来创建步进序列，即每两个索引位置之间的间隔\n",
    "nba.iloc[0:10:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Milwaukee Bucks'"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#4.7.3 从特定列中提取值\n",
    "# loc 和 iloc 属性都接受要提取的列的参数。如果使用 loc ，必须提供列名。如果使用 iloc ，必须提供位置\n",
    "# 使用 loc 在 Giannis Antetokounmpo 行和 Team 列的交叉点提取值\n",
    "nba.loc['Giannis Antetokounmpo','Team']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Position                     PG\n",
       "Birthday    1989-08-26 00:00:00\n",
       "Name: James Harden, dtype: object"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 指定多个值，可以将参数的列表传递给 loc\n",
    "# 提取带有 James Harden 索引标签的行，以及来自 Position 列和 Birthday 的列\n",
    "nba.loc['James Harden',[\"Position\",'Birthday']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Russell Westbrook</th>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>38506482</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Anthony Davis</th>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>27093019</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 Team    Salary\n",
       "Name                                           \n",
       "Russell Westbrook     Houston Rockets  38506482\n",
       "Anthony Davis      Los Angeles Lakers  27093019"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 多个行标签和多个列标签\n",
    "nba.loc[['Russell Westbrook','Anthony Davis'],['Team','Salary']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Position                      C\n",
       "Birthday    1994-03-16 00:00:00\n",
       "Salary                 27504630\n",
       "Name: Joel Embiid, dtype: object"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用切片语法来提取多列。提取从 Position 到 Salary 的所有列\n",
    "nba.loc['Joel Embiid',\"Position\":\"Salary\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Series([], Name: Joel Embiid, dtype: object)"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 必须按照列在 DataFrame 中出现的顺序传递列名，顺序错误的话，就无法识别，产生一个空结果\n",
    "nba.loc['Joel Embiid',\"Salary\":\"Position\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "UsageError: Line magic function `%%timeit` not found.\n"
     ]
    }
   ],
   "source": [
    "# iloc 使用索引位置获取值。获取行索引位置57处和列索引位置3处的交点处的值\n",
    "nba.iloc[57,3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "UsageError: Line magic function `%%timeit` not found.\n"
     ]
    }
   ],
   "source": [
    "# 使用列表切片语法，获得从索引位置100到索引位置104的所有行记录，包括从列开头到索引位置3处的列（Salary）的所有列\n",
    "nba.iloc[100:104,:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('1992-08-01 00:00:00')"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# loc 和 iloc 访问器应用非常广泛，方括号中接受单个值，值列表，列表切片等，由于灵活性高，需要额外的性能开销。\n",
    "# 提取单个值的时候，使用 at 和 iat 替代，具有明显的速度优势\n",
    "nba.at['Austin Rivers',\"Birthday\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "29.5 µs ± 532 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%%timeit\n",
    "nba.iat[263,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "29802321"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4.8 从 Series 中提取值\n",
    "nba['Salary'].loc['Damian Lillard']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "29802321"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba['Salary'].at['Damian Lillard']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2033160"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba['Salary'].iloc[234]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2033160"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba['Salary'].iat[234]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Team', 'Position', 'Birthday', 'Salary'], dtype='object')"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对行或列进行重命名\n",
    "nba.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Date of Birth</th>\n",
       "      <th>Pay</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                            Team Position Date of Birth      Pay\n",
       "Name                                                            \n",
       "Shake Milton  Philadelphia 76ers       SG    1996-09-26  1445697"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.columns=['Team','Position','Date of Birth','Pay']\n",
    "nba.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Pay</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christian Wood</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derrick Rose</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marial Shayok</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Austin Rivers</th>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1992-08-01</td>\n",
       "      <td>2174310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Harry Giles</th>\n",
       "      <td>Sacramento Kings</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-04-22</td>\n",
       "      <td>2578800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Robin Lopez</th>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>4767000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Collin Sexton</th>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1999-01-04</td>\n",
       "      <td>4764960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ricky Rubio</th>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-10-21</td>\n",
       "      <td>16200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Team Position   Birthday       Pay\n",
       "Name                                                             \n",
       "Shake Milton     Philadelphia 76ers       SG 1996-09-26   1445697\n",
       "Christian Wood      Detroit Pistons       PF 1995-09-27   1645357\n",
       "PJ Washington     Charlotte Hornets       PF 1998-08-23   3831840\n",
       "Derrick Rose        Detroit Pistons       PG 1988-10-04   7317074\n",
       "Marial Shayok    Philadelphia 76ers        G 1995-07-26     79568\n",
       "...                             ...      ...        ...       ...\n",
       "Austin Rivers       Houston Rockets       PG 1992-08-01   2174310\n",
       "Harry Giles        Sacramento Kings       PF 1998-04-22   2578800\n",
       "Robin Lopez         Milwaukee Bucks        C 1988-04-01   4767000\n",
       "Collin Sexton   Cleveland Cavaliers       PG 1999-01-04   4764960\n",
       "Ricky Rubio            Phoenix Suns       PG 1990-10-21  16200000\n",
       "\n",
       "[450 rows x 4 columns]"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.rename(columns={'Date of Birth':'Birthday'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 操作持久化\n",
    "nba = nba.rename(columns={\"Date of Birth\":\"Birthday\"})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 通过rename方法，传入 index 来重命名索引标签\n",
    "nba = nba.rename(index={'Giannis Antetokounmpo':'Greek Freak'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Team            Milwaukee Bucks\n",
       "Position                     PF\n",
       "Birthday    1994-12-06 00:00:00\n",
       "Pay                    25842697\n",
       "Name: Greek Freak, dtype: object"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.loc['Greek Freak']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Pay</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Team</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Philadelphia 76ers</th>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Detroit Pistons</th>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Charlotte Hornets</th>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Detroit Pistons</th>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Philadelphia 76ers</th>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   Position   Birthday      Pay\n",
       "Team                                           \n",
       "Philadelphia 76ers       SG 1996-09-26  1445697\n",
       "Detroit Pistons          PF 1995-09-27  1645357\n",
       "Charlotte Hornets        PF 1998-08-23  3831840\n",
       "Detroit Pistons          PG 1988-10-04  7317074\n",
       "Philadelphia 76ers        G 1995-07-26    79568"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4.10 重置索引\n",
    "# 把 Team 列设置为 nba 的索引，使用 set_index 方法，会造成已有的索引 Name 丢失\n",
    "nba.set_index(\"Team\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Pay</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Shake Milton</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Christian Wood</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>PJ Washington</td>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Derrick Rose</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Marial Shayok</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             Name                Team Position   Birthday      Pay\n",
       "0    Shake Milton  Philadelphia 76ers       SG 1996-09-26  1445697\n",
       "1  Christian Wood     Detroit Pistons       PF 1995-09-27  1645357\n",
       "2   PJ Washington   Charlotte Hornets       PF 1998-08-23  3831840\n",
       "3    Derrick Rose     Detroit Pistons       PG 1988-10-04  7317074\n",
       "4   Marial Shayok  Philadelphia 76ers        G 1995-07-26    79568"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 为了保留已有的索引数据，使用 reset_index 方法把当前的索引移动到 DataFrame 列\n",
    "nba.reset_index().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Pay</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Team</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Philadelphia 76ers</th>\n",
       "      <td>Shake Milton</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Detroit Pistons</th>\n",
       "      <td>Christian Wood</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Charlotte Hornets</th>\n",
       "      <td>PJ Washington</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Detroit Pistons</th>\n",
       "      <td>Derrick Rose</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Philadelphia 76ers</th>\n",
       "      <td>Marial Shayok</td>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                              Name Position   Birthday      Pay\n",
       "Team                                                           \n",
       "Philadelphia 76ers    Shake Milton       SG 1996-09-26  1445697\n",
       "Detroit Pistons     Christian Wood       PF 1995-09-27  1645357\n",
       "Charlotte Hornets    PJ Washington       PF 1998-08-23  3831840\n",
       "Detroit Pistons       Derrick Rose       PG 1988-10-04  7317074\n",
       "Philadelphia 76ers   Marial Shayok        G 1995-07-26    79568"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 然后使用 set_index 设置索引\n",
    "nba.reset_index().set_index('Team').head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 4.11 代码挑战\n",
    "# nfl.csv 文件包含美国国家橄榄球联盟中与NBA相似的数据结构，包括球员的 Name,Team ,Position, Birthday 和 Salary 信息，尝试回答如下问题\n",
    "# 1. 如何导入 csv 文件，并将其 Birthday 列中的值转换为日期时间类型\n",
    "# 2. 可以通过哪两种方式设置 DataFrame 索引来存储球员信息\n",
    "# 3. 如何计算这个数据集中每支球队的球员人数\n",
    "# 4. 收入最高的5名球员是谁\n",
    "# 5. 如何先按球队名称升序对数据集进行排序，然后按薪资降序对数据集进行排序\n",
    "# 6. New York Jets 队年龄最大的球员是谁，他的生日是哪天"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tremon Smith</th>\n",
       "      <td>Philadelphia Eagles</td>\n",
       "      <td>RB</td>\n",
       "      <td>1996-07-20</td>\n",
       "      <td>570000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Shawn Williams</th>\n",
       "      <td>Cincinnati Bengals</td>\n",
       "      <td>SS</td>\n",
       "      <td>1991-05-13</td>\n",
       "      <td>3500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Adam Butler</th>\n",
       "      <td>New England Patriots</td>\n",
       "      <td>DT</td>\n",
       "      <td>1994-04-12</td>\n",
       "      <td>645000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derek Wolfe</th>\n",
       "      <td>Denver Broncos</td>\n",
       "      <td>DE</td>\n",
       "      <td>1990-02-24</td>\n",
       "      <td>8000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jake Ryan</th>\n",
       "      <td>Jacksonville Jaguars</td>\n",
       "      <td>OLB</td>\n",
       "      <td>1992-02-27</td>\n",
       "      <td>1000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bashaud Breeland</th>\n",
       "      <td>Kansas City Chiefs</td>\n",
       "      <td>CB</td>\n",
       "      <td>1992-01-30</td>\n",
       "      <td>805000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Craig James</th>\n",
       "      <td>Philadelphia Eagles</td>\n",
       "      <td>CB</td>\n",
       "      <td>1996-04-29</td>\n",
       "      <td>570000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jonotthan Harrison</th>\n",
       "      <td>New York Jets</td>\n",
       "      <td>C</td>\n",
       "      <td>1991-08-25</td>\n",
       "      <td>1500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chuma Edoga</th>\n",
       "      <td>New York Jets</td>\n",
       "      <td>OT</td>\n",
       "      <td>1997-05-25</td>\n",
       "      <td>495000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tajae Sharpe</th>\n",
       "      <td>Tennessee Titans</td>\n",
       "      <td>WR</td>\n",
       "      <td>1994-12-23</td>\n",
       "      <td>2025000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1655 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    Team Position   Birthday   Salary\n",
       "Name                                                                 \n",
       "Tremon Smith         Philadelphia Eagles       RB 1996-07-20   570000\n",
       "Shawn Williams        Cincinnati Bengals       SS 1991-05-13  3500000\n",
       "Adam Butler         New England Patriots       DT 1994-04-12   645000\n",
       "Derek Wolfe               Denver Broncos       DE 1990-02-24  8000000\n",
       "Jake Ryan           Jacksonville Jaguars      OLB 1992-02-27  1000000\n",
       "...                                  ...      ...        ...      ...\n",
       "Bashaud Breeland      Kansas City Chiefs       CB 1992-01-30   805000\n",
       "Craig James          Philadelphia Eagles       CB 1996-04-29   570000\n",
       "Jonotthan Harrison         New York Jets        C 1991-08-25  1500000\n",
       "Chuma Edoga                New York Jets       OT 1997-05-25   495000\n",
       "Tajae Sharpe            Tennessee Titans       WR 1994-12-23  2025000\n",
       "\n",
       "[1655 rows x 4 columns]"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1. 如何导入 csv 文件，并将其 Birthday 列中的值转换为日期时间类型\n",
    "nfl = pd.read_csv(\"./file/chapter_04/nfl.csv\", parse_dates=['Birthday'], date_format={\"Birthday\": 'mixed'},index_col='Name')\n",
    "nfl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tremon Smith</th>\n",
       "      <td>Philadelphia Eagles</td>\n",
       "      <td>RB</td>\n",
       "      <td>1996-07-20</td>\n",
       "      <td>570000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Shawn Williams</th>\n",
       "      <td>Cincinnati Bengals</td>\n",
       "      <td>SS</td>\n",
       "      <td>1991-05-13</td>\n",
       "      <td>3500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Adam Butler</th>\n",
       "      <td>New England Patriots</td>\n",
       "      <td>DT</td>\n",
       "      <td>1994-04-12</td>\n",
       "      <td>645000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derek Wolfe</th>\n",
       "      <td>Denver Broncos</td>\n",
       "      <td>DE</td>\n",
       "      <td>1990-02-24</td>\n",
       "      <td>8000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jake Ryan</th>\n",
       "      <td>Jacksonville Jaguars</td>\n",
       "      <td>OLB</td>\n",
       "      <td>1992-02-27</td>\n",
       "      <td>1000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bashaud Breeland</th>\n",
       "      <td>Kansas City Chiefs</td>\n",
       "      <td>CB</td>\n",
       "      <td>1992-01-30</td>\n",
       "      <td>805000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Craig James</th>\n",
       "      <td>Philadelphia Eagles</td>\n",
       "      <td>CB</td>\n",
       "      <td>1996-04-29</td>\n",
       "      <td>570000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jonotthan Harrison</th>\n",
       "      <td>New York Jets</td>\n",
       "      <td>C</td>\n",
       "      <td>1991-08-25</td>\n",
       "      <td>1500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chuma Edoga</th>\n",
       "      <td>New York Jets</td>\n",
       "      <td>OT</td>\n",
       "      <td>1997-05-25</td>\n",
       "      <td>495000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tajae Sharpe</th>\n",
       "      <td>Tennessee Titans</td>\n",
       "      <td>WR</td>\n",
       "      <td>1994-12-23</td>\n",
       "      <td>2025000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1655 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    Team Position   Birthday   Salary\n",
       "Name                                                                 \n",
       "Tremon Smith         Philadelphia Eagles       RB 1996-07-20   570000\n",
       "Shawn Williams        Cincinnati Bengals       SS 1991-05-13  3500000\n",
       "Adam Butler         New England Patriots       DT 1994-04-12   645000\n",
       "Derek Wolfe               Denver Broncos       DE 1990-02-24  8000000\n",
       "Jake Ryan           Jacksonville Jaguars      OLB 1992-02-27  1000000\n",
       "...                                  ...      ...        ...      ...\n",
       "Bashaud Breeland      Kansas City Chiefs       CB 1992-01-30   805000\n",
       "Craig James          Philadelphia Eagles       CB 1996-04-29   570000\n",
       "Jonotthan Harrison         New York Jets        C 1991-08-25  1500000\n",
       "Chuma Edoga                New York Jets       OT 1997-05-25   495000\n",
       "Tajae Sharpe            Tennessee Titans       WR 1994-12-23  2025000\n",
       "\n",
       "[1655 rows x 4 columns]"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2. 可以通过哪两种方式设置 DataFrame 索引来存储球员信息\n",
    "nfl.set_index('Name')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Team\n",
       "New York Jets           58\n",
       "Kansas City Chiefs      56\n",
       "Washington Redskins     56\n",
       "New Orleans Saints      55\n",
       "San Francisco 49Ers     55\n",
       "Denver Broncos          54\n",
       "Minnesota Vikings       54\n",
       "Los Angeles Chargers    54\n",
       "Seattle Seahawks        53\n",
       "Dallas Cowboys          53\n",
       "Buffalo Bills           53\n",
       "Atlanta Falcons         53\n",
       "Detroit Lions           53\n",
       "Chicago Bears           53\n",
       "Los Angeles Rams        52\n",
       "New York Giants         52\n",
       "Philadelphia Eagles     52\n",
       "Houston Texans          52\n",
       "Arizona Cardinals       51\n",
       "Cincinnati Bengals      51\n",
       "Green Bay Packers       51\n",
       "Oakland Raiders         51\n",
       "Jacksonville Jaguars    50\n",
       "Cleveland Browns        49\n",
       "Miami Dolphins          49\n",
       "Indianapolis Colts      49\n",
       "Carolina Panthers       49\n",
       "New England Patriots    49\n",
       "Baltimore Ravens        48\n",
       "Pittsburgh Steelers     47\n",
       "Tampa Bay Buccaneers    47\n",
       "Tennessee Titans        46\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3. 如何计算这个数据集中每支球队的球员人数\n",
    "nfl['Team'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Kirk Cousins</th>\n",
       "      <td>Minnesota Vikings</td>\n",
       "      <td>QB</td>\n",
       "      <td>1988-08-19</td>\n",
       "      <td>27500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jameis Winston</th>\n",
       "      <td>Tampa Bay Buccaneers</td>\n",
       "      <td>QB</td>\n",
       "      <td>1994-01-06</td>\n",
       "      <td>20922000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marcus Mariota</th>\n",
       "      <td>Tennessee Titans</td>\n",
       "      <td>QB</td>\n",
       "      <td>1993-10-30</td>\n",
       "      <td>20922000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derek Carr</th>\n",
       "      <td>Oakland Raiders</td>\n",
       "      <td>QB</td>\n",
       "      <td>1991-03-28</td>\n",
       "      <td>19900000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jimmy Garoppolo</th>\n",
       "      <td>San Francisco 49Ers</td>\n",
       "      <td>QB</td>\n",
       "      <td>1991-11-02</td>\n",
       "      <td>17200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 Team Position   Birthday    Salary\n",
       "Name                                                               \n",
       "Kirk Cousins        Minnesota Vikings       QB 1988-08-19  27500000\n",
       "Jameis Winston   Tampa Bay Buccaneers       QB 1994-01-06  20922000\n",
       "Marcus Mariota       Tennessee Titans       QB 1993-10-30  20922000\n",
       "Derek Carr            Oakland Raiders       QB 1991-03-28  19900000\n",
       "Jimmy Garoppolo   San Francisco 49Ers       QB 1991-11-02  17200000"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4. 收入最高的5名球员是谁\n",
    "nfl.sort_values('Salary', ascending=False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A'Shawn Robinson</th>\n",
       "      <td>Detroit Lions</td>\n",
       "      <td>DT</td>\n",
       "      <td>1995-03-21</td>\n",
       "      <td>1163678</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A.J. Brown</th>\n",
       "      <td>Tennessee Titans</td>\n",
       "      <td>WR</td>\n",
       "      <td>1997-06-30</td>\n",
       "      <td>495000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A.J. Moore</th>\n",
       "      <td>Houston Texans</td>\n",
       "      <td>SS</td>\n",
       "      <td>1995-12-15</td>\n",
       "      <td>570000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aaron Brewer</th>\n",
       "      <td>Arizona Cardinals</td>\n",
       "      <td>LS</td>\n",
       "      <td>1990-07-05</td>\n",
       "      <td>930000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aaron Colvin</th>\n",
       "      <td>Washington Redskins</td>\n",
       "      <td>CB</td>\n",
       "      <td>1991-10-02</td>\n",
       "      <td>7500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zack Martin</th>\n",
       "      <td>Dallas Cowboys</td>\n",
       "      <td>G</td>\n",
       "      <td>1990-11-20</td>\n",
       "      <td>10000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zaire Franklin</th>\n",
       "      <td>Indianapolis Colts</td>\n",
       "      <td>OLB</td>\n",
       "      <td>1996-07-02</td>\n",
       "      <td>570000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zak DeOssie</th>\n",
       "      <td>New York Giants</td>\n",
       "      <td>LS</td>\n",
       "      <td>1984-05-24</td>\n",
       "      <td>1030000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zane Gonzalez</th>\n",
       "      <td>Arizona Cardinals</td>\n",
       "      <td>K</td>\n",
       "      <td>1995-05-07</td>\n",
       "      <td>645000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zay Jones</th>\n",
       "      <td>Oakland Raiders</td>\n",
       "      <td>WR</td>\n",
       "      <td>1995-03-30</td>\n",
       "      <td>1081348</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1655 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 Team Position   Birthday    Salary\n",
       "Name                                                               \n",
       "A'Shawn Robinson        Detroit Lions       DT 1995-03-21   1163678\n",
       "A.J. Brown           Tennessee Titans       WR 1997-06-30    495000\n",
       "A.J. Moore             Houston Texans       SS 1995-12-15    570000\n",
       "Aaron Brewer        Arizona Cardinals       LS 1990-07-05    930000\n",
       "Aaron Colvin      Washington Redskins       CB 1991-10-02   7500000\n",
       "...                               ...      ...        ...       ...\n",
       "Zack Martin            Dallas Cowboys        G 1990-11-20  10000000\n",
       "Zaire Franklin     Indianapolis Colts      OLB 1996-07-02    570000\n",
       "Zak DeOssie           New York Giants       LS 1984-05-24   1030000\n",
       "Zane Gonzalez       Arizona Cardinals        K 1995-05-07    645000\n",
       "Zay Jones             Oakland Raiders       WR 1995-03-30   1081348\n",
       "\n",
       "[1655 rows x 4 columns]"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 5. 如何先按球队名称升序对数据集进行排序，然后按薪资降序对数据集进行排序\n",
    "nfl.sort_values(by=['Name', 'Salary'],ascending=[True, False])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Team</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>New York Jets</th>\n",
       "      <td>Ryan Kalil</td>\n",
       "      <td>C</td>\n",
       "      <td>1985-03-29</td>\n",
       "      <td>2400000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     Name Position   Birthday   Salary\n",
       "Team                                                  \n",
       "New York Jets  Ryan Kalil        C 1985-03-29  2400000"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 6. New York Jets 队年龄最大的球员是谁，他的生日是哪天\n",
    "nfl.reset_index().set_index(\"Team\").loc['New York Jets'].sort_values(by=['Birthday'], ascending=True).head(1)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.10 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "c585f91d3623973be3accc48b0d5e967ce904a396a0f0c8bda7b100d8b60333f"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
